/**
 * Created by no1 on 2015/6/27.
 */

'use strict';

/**
 * Module wareEdition.
 */

var mongoose = require('mongoose');
var ObjectId = mongoose.Schema.ObjectId;
var Mixed = mongoose.Schema.Types.Mixed;
var extend = require('mongoose-schema-extend');

var baseSchema = require('./base.js').baseSchema;


module.exports = {
  wareSchema: baseSchema.extend({
    //id
    id: {
      type: Number,
      required: true,
      unique: true,
      index: true
    },
    //商品类别
    categories: [{
      name: String,
      pCode: Number,
      code: {
        type: Number,
        index: true
      }
    }],

    //商家id
    vendorid: {
      type: Number,
      index: true
    },
    //商品所在的店面集合
    shops: [{
      shopInfo: {
        type: ObjectId,
        ref: 'shop'
      },
      //店面id
      sid: {
        type: Number,
        index: true
      },
      //商店名称
      sName: String,
      //店面坐标
      loc: {
        type: [Number],
        index: '2d'
      },
      //地区
      district: [{
        name: String,
        pCode: Number,
        code: {
          type: Number,
          index: true
        }
      }],
      //商品在这店的价格
      sPrice: {
        type: Number,
        min: 0
      },
      //商品在这店的库存
      sAmount: {
        type: Number,
        min: 0
      }
    }],
    //商品版本
    version: Number,
    //图片ID
    images: [String],
    //市场售价
    marketPrice: Number,
    //售价
    price: Number,
    //商品总数
    totalQuantity: Number,
    //已经购买的数量
    buyNumber: Number,


    //评价得分 满分5分
    eTotal: {
      type: Number,
      index: true
    },
    //评价总数
    eCount: Number,
    //平均评价得分 eAverage=eTotal/eCount
    eAverage: Number,
    //评估 估计
    esTimate: Number,
    //环境评价
    decorationGrade: Number,
    //服务评价
    serviceGrade: Number,
    //支付方式 1:到店支付；2支付宝支付；3：微信支付
    payWay: Number,
    //优惠
    discount: {
      type: Number,
      index: true
    },
    //预订
    reservation: {
      type: Number,
      index: true
    },
    //服务类型
    services: [
      {
        code: Number,
        name: String
      }
    ],
    //通知
    notice: String,
    //特惠详情
    discountDetails: [
      {
        item: [
          {
            name: String,
            number: Number,
            price: Number
          }
        ]
      }

    ],
    //购买须知
    notesToBuy: [
      {
        name: String,
        content: [String]
      }
    ],

    //销售开始时间
    onLineTime: Date,
    //销售结束时间
    offLineTtime: Date,
    //除外时间
    exceptTime: [
      {
        begin: Date,
        end: Date
      }
    ],
    //除外时间的信息
    exceptTimeInfo: String,
    //图文详情
    graphicDetails: String,
    //其他
    otherInfo: {
      type: Mixed
    }
  })
}
